<?php
/**
 * Stack trace class.
 *
 *
 *
 * @package OWL
 * @subpackage Core
 * @since 1.0
 *
 * @author KeiMOon
 */
class Owl_Stack_Trace {

   /**
     * Singleton instance
     *
     * @var Stack_Trace
     */
    private static $_instance;

    /**
     * Error container
     *
     * @var Array
     */
    private $_error_containter = array();

    /**
     * Constructor, cannot be accessed.
     */
    private function  __construct() {

    }

    /**
     * Clone method, cannot be accessed.
     */
    private function __clone() {

    }

    /**
     * Object initialization method. Use this method instead of new operator.
     *
     * @return Stack_Trace singleton instance
     */
    static function get_instance() {
        if( self::$_instance === NULL ) {
            self::$_instance = new self();
        }
        return self::$_instance;
    }

    function raise( $group, $message ) {
        if ( !is_string( $message ) ) {
            return false;
        }
        $this->_error_containter[$group][] = $message;
    }

    function error_has_been_raised( $group ) {
        return isset( $this->_error_containter[$group] );
    }

    function print_error( $group ) {
        if ( !$this->error_has_been_raised( $group ) ) {
            return false;
        }
        else {
            echo Owl_Html::make_it_list( $this->_error_containter[$group] );
            $this->suppress_error( $group );
        }
    }

    function suppress_error( $group ) {
        if ( $this->error_has_been_raised( $group ) ) {
            unset( $this->_error_containter[$group] );
        }
    }
}


